unit Con_Comissao;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids, db, dbtables;

type
  TFrmCon_Comissao = class(TFrmConsulta)
    Label2: TLabel;
    ed_coluna: TEdit;
    dbg: TDBGrid;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure ed_colunaKeyPress(Sender: TObject; var Key: Char);
    procedure ed_colunaExit(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
  private
    procedure FazConsulta;
    { Private declarations }
  public
    xcodigo_com : string;
    { Public declarations }
  end;

var
  FrmCon_Comissao: TFrmCon_Comissao;

implementation

uses Biblio, Dm, clsComissao, Cad_Comissao;

var comissao : TComissao;
    tds    : Tdatasource;
    tq     : Tquery;

{$R *.DFM}

procedure TFrmCon_Comissao.FormCreate(Sender: TObject);
begin
  inherited;
  comissao := TComissao.create;
end;

procedure TFrmCon_Comissao.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  comissao.free;
end;

procedure TFrmCon_Comissao.FormActivate(Sender: TObject);
begin
  inherited;
  tds             := TDataSource.create(frmCad_Comissao);
  tq              := Tquery.create(frmCad_Comissao);
  tq.databasename := dmint.db.databasename;
  tq.active       := False;
  tds.DataSet     := tq;
  dbg.DataSource  := tds;
  FazConsulta;
  ed_coluna.setfocus;
end;

procedure TFrmCon_Comissao.FazConsulta;
begin
  If trim(ed_coluna.text) = '' then
    comissao.Consultartodos(tq)
  else
    comissao.Consultar(tq,ed_coluna.text);
  tq.open;
  dbg.DataSource := tds;
  dbg.Refresh;
end;

procedure TFrmCon_Comissao.ed_colunaKeyPress(Sender: TObject;
  var Key: Char);
begin
  inherited;
  if key>=':' then abort;
  if (key>=' ') and (key<='/') then abort;
end;

procedure TFrmCon_Comissao.ed_colunaExit(Sender: TObject);
begin
  inherited;
  FazConsulta;
end;

procedure TFrmCon_Comissao.BtnFecharClick(Sender: TObject);
begin
  inherited;
  xcodigo_com := tq.fieldbyname('com_Codigo').asstring;
  tds.free;
  tq.free;
end;

end.
